<template>
	<view class="change-pwd-box">
		<view class="form-box">
			<view class="list-cell">
				<input class="sl-input" v-model="newPassword" :password="showPassword1" placeholder="请输入新密码" />
				<view class="show-hide-box" @tap="changePsdType1">
					<image  class="show-hide-img" :src="showPassword1?'/static/shilu-login/show.png':'/static/shilu-login/hide.png'"></image>
				</view>
			</view>
			<view class="list-cell">
				<input class="sl-input" v-model="againPassword" :password="showPassword2" placeholder="请再次输入密码" />
				<view class="show-hide-box" @tap="changePsdType2">
					<image  class="show-hide-img" :src="showPassword2?'/static/shilu-login/show.png':'/static/shilu-login/hide.png'"></image>
				</view>
			</view>
			<view class="list-cell">
				<input class="sl-input" v-model="vPhoneNum" type="text" placeholder="请输入手机验证码" />
				<text class="sl-btn" :class="(second>0 || sendBtnDis)?'disabled':''"
					@tap="sendMsg">{{yanzhengma}}</text>
			</view>

		</view>

		<view class="change-pwd-btn" :class="loginBtnDis?'disabled':''" @tap="bindLogin">下一步</view>
	</view>
</template>

<script>
	import request from "../../request/request.js"
	var _this, js;
	export default {
		data() {
			return {
				newPassword: '',
				againPassword: '',
				vPhoneNum:'',
				second: -1,
				showPassword1:true,
				showPassword2:true,
			};
		},
		onLoad() {
			_this = this;
		},
		onUnload() {
			clearInterval(js)
			this.second = -1;
			this.clear()
		},
		computed: {
			yanzhengma() {
				if (this.second == -1) {
					return '获取验证码';
				}else if (this.second == 0) {
					return '重新发送';
				} else {
					if (this.second < 10) {
						return '0' + this.second  +'S';
					} else {
						return  this.second + 'S';
					}
				}
			},
			loginBtnDis() {
				return !this.newPassword || !this.againPassword || !this.vPhoneNum
			},
			sendBtnDis() {
				return !this.newPassword || !this.againPassword
			}

		},
		methods: {
			changePsdType1(){
				this.showPassword1 = !this.showPassword1;
			},
			changePsdType2(){
				this.showPassword2 = !this.showPassword2;
			},
			clear() {
				clearInterval(js)
				js = null
				this.second = 0
			},
			sendMsg() {
				if (this.second > 0) {
					return;
				}
				this.second = 60;
				//请求业务
				js = setInterval(() => {
					_this.second--;
					if (_this.second == 0) {
						_this.clear()
					}
				}, 1000)
			},
			dialogInputClose() {
				this.$refs.inputDialog.close();
			},
			bindLogin() {
				if (this.loginBtnDis) {
					return
				}
				if (!this.newPassword) {
					uni.showToast({
						icon: 'none',
						title: '密码不能为空!'
					});
					return;
				}
				if (!this.againPassword) {
					uni.showToast({
						icon: 'none',
						title: '确认密码不能为空!'
					});
					return;
				}
				if (this.newPassword != this.againPassword) {
					uni.showToast({
						icon: 'none',
						title: '两次密码不一样!'
					});
					return;
				}
				if (!this.vPhoneNum) {
					uni.showToast({
						icon: 'none',
						title: '手机验证码不能为空!'
					});
					return;
				}
				uni.redirectTo({
					url: '/pages/faceIdentification/faceIdentification'
				});
				//
				// request.request({
				// 	url: '/api/login/login',
				// 	data: {
				// 		loginName: this.phone,
				// 		password: this.password
				// 	},
				// 	method: 'POST',
				// 	dataType: 'json',
				// }).then(res => {
				// 	if (res.data.code != 200) {
				// 		uni.showToast({
				// 			title: res.data.msg,
				// 			icon: 'none'
				// 		});
				// 	} else {
				// 		//成功后的逻辑
				// 		uni.navigateBack();
				// 	}
				// });
			},
			toChangePwd(){
				this.$refs.firstLoginDialog.close()
			},
			toLogin(){
				this.$refs.firstLoginDialog.close()
			}
		}
	}
</script>

<style>
	.change-pwd-box {
		width: 100%;
		height: 100%;
		background-color: #F8F9Fc;
	
	}

	.form-box {
		display: flex;
		flex-direction: column;
		padding: 27rpx 30rpx 20rpx;
		background-color: #FFFFFF;
	}

	.list-cell {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		height: 96rpx;
		color: #333333;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.sl-tile {
		width: 208rpx;
		font-family: PingFangSC-Regular;
		font-size: 32rpx;
		color: #333333;
		letter-spacing: 0;
		font-weight: 400;
	}

	.list-cell .sl-input {
		flex: 1;
		text-align: left;
		font-size: 32rpx;
	}

	.sl-btn {
		font-family: PingFangSC-Regular;
		font-size: 24rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 24rpx;
		font-weight: 400;
		background: #315EFB;
		border-radius: 8rpx;
		padding: 16rpx;
		width: 160rpx;
		
	}

	.show-hide-box {
		width: 80rpx;
		height: 96rpx;
		text-align: center;
	}

	.show-hide-img {
		width: 48rpx;
		height: 48rpx;
		margin-top: 30rpx;
	}

	.change-pwd-btn {
		color: #FFFFFF;
		font-size: 32rpx;
		width: 670rpx;
		height: 98rpx;
		line-height: 98rpx;
		background: #315EFB;
		border-radius: 49rpx;
		text-align: center;
		margin: 206rpx auto 0;

	}

	.disabled {
		opacity: 0.6;
	}

</style>